package net.sxnic.workflow.handler.action;

import net.sxnic.comm.utils.CommUtils;
import net.sxnic.workflow.handler.Handler;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Save extends HandlerAction {
	
	private Logger logger = LoggerFactory.getLogger(Save.class);
	
	private String className;
	
	private String handlerAction;
	
	public void prepare() throws Exception {
		node = nodManager.get(nodeId);
	}

	public String execute() throws Exception {
		String[] classNames = StringUtils.split(CommUtils.splitTrim(className, ","), ",");
		String[] handlerActions = StringUtils.split(handlerAction, ",");
		
		node.getHandlers().clear();
		
		Handler handler = null;
		int length = classNames.length;
		for(int i =0;i<length;i++){
			handler = new Handler();
			handler.setClassName(classNames[i]);
			handler.setAction(StringUtils.replace(handlerActions[i].trim(), ";", ","));
			
			logger.debug("===管理员调整node's handlers成功===={}=={}",classNames[i],handler.getAction());
			node.getHandlers().add(handler);
		}
		
		nodManager.update(node);
		msg ="saveSuccess";
		
		return SUCCESS;
	}
	

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getHandlerAction() {
		return handlerAction;
	}

	public void setHandlerAction(String handlerAction) {
		this.handlerAction = handlerAction;
	}

	

}
